<?php

error_reporting(E_ALL);

/**
 * cn.solor.dig - class.CommonAnalyzer.php
 *
 * $Id: class.CommonAnalyzer.php,v 1.2 2008-01-14 15:32:04 rainx Exp $
 *
 * This file is part of cn.solor.dig.
 *
 * Automatic generated with ArgoUML 0.22 on 17.12.2006, 10:07:15
 *
 * @author firstname and lastname of author, <author@example.org>
 */

if (0 > version_compare(PHP_VERSION, '5')) {
    die('This file was generated for PHP 5');
}

/**
 * include BasicAnalyzer
 *
 * @author firstname and lastname of author, <author@example.org>
 */
//require_once('class.BasicAnalyzer.php');

/* user defined includes */
// section 127-0-0-1--5e4d4b42:10f8dcad467:-8000:0000000000000811-includes begin
// section 127-0-0-1--5e4d4b42:10f8dcad467:-8000:0000000000000811-includes end

/* user defined constants */
// section 127-0-0-1--5e4d4b42:10f8dcad467:-8000:0000000000000811-constants begin
// section 127-0-0-1--5e4d4b42:10f8dcad467:-8000:0000000000000811-constants end

/**
 * Short description of class CommonAnalyzer
 *
 * @access public
 * @author firstname and lastname of author, <author@example.org>
 */
class CommonAnalyzer
    extends BasicAnalyzer
        implements Analyzer
{
    // --- ATTRIBUTES ---

    public $features = array('url' => '/^(http|https|ftp|file).+/i');

    // --- OPERATIONS ---

    /**
     * Short description of method analyze
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @param string
     * @return array
     */
    public function analyze($content, $url)
    {
        $all_video = array();
        ///////////////////////////////////////////////////////////////////////////////
        ///// The following code snippit Grabbed from old solor code              /////
        ///////////////////////////////////////////////////////////////////////////////
        
        // 取得title
        preg_match("/<title(.*)>(.*)<\/title>/i", $content, $ret);

        if(!empty($ret[2]))
        {
            $title = $ret[2];
            $descr = $ret[2];
        }
        else
        {
            $title = "";
            $descr = "";
        }
        
        // get hostname of url  ....
        preg_match("/http:\/\/[^\/]+/i", $url, $hn);

        if (!empty($hn[0]))
        {
            $target_hostname = $hn[0];
        }
        else
        {
            $target_hostname = $url;
        }
        $url_len = strlen($url);
        for($i = $url_len -1 ; $url{$i} != '/' ; $i--);
        $target_path = substr($url, 0, $i+1);
        //   echo $content;
        preg_match_all("/(mms|mmst|http|rtsp|ftp):\/\/[^ \"\'=]+\.(wmv|rmvb|rm|mp3|wma|mov)/i" , $content, $result);
        $all_video  = $result[0];
        // {{{ get base href attribute of html
        preg_match("/<base[^>]*href=[\'\" ]?([^> \'\"\t]*)/i", $content, $re);
        if (count($re) >= 2)
            $basehref = $re[1];
        // }}}

        preg_match_all("/(\'|\"|=)([^ \"\'=]+\.)(wmv|rmvb|rm|mp3|wma|mov)/i", $content, $result);
        for($i = 0; $i < count($result[2]); $i++)
        {
            if (!in_array($result[2][$i] . $result[3][$i], $all_video))
            {
                if ($result[2][$i]{0} == '/')
                {
                    array_push($all_video, $target_hostname . $result[2][$i] . $result[3][$i]);
                }
                else
                {
                    array_push($all_video, $target_path .  $result[2][$i] . $result[3][$i]);
                }
            }
        }

        /////// constuct return array
        $retarr = array();
        foreach ($all_video as $video)
        {
            $retarr[] = array(
                   "url" => $video, /* 视频对应的url */
                   "title" => $title , //视频对应的title index
                   "tags" => array("sr_other"), // index
                   "descr" => $descr, //视频对应的描述信息 index
                   "referer" => $url, //视频下载需要的referer信息
                   "category" => "sr_other", //视频的分类
                   "ext" => "", // 视频的后缀类型
                   "pub_date" => time() , // 视频发布时间的unix time stamp
                   "author" => ""  // 视频的作者
                );
        }

        ////////////////////////////////////////////////////
        return (array) $retarr;
    }

} /* end of class CommonAnalyzer */
?>
